//
//  ChainCheckNewVersion.m
//  Chain
//
//  Created by zhaosh on 2018/4/17.
//  Copyright © 2018年 zhaosh. All rights reserved.
//

#import "ChainCheckNewVersion.h"

NSString *const kNewVersonKey = @"isHaveNewVersion";

@interface ChainCheckNewVersion()

@end

@implementation ChainCheckNewVersion
// 新版本的获取服务器上ipa的版本号
+(void)isHaveNewVersion:(isHaveNewVersionBlock)block{
    NSDictionary *infoDic =[NSBundle mainBundle].infoDictionary;
    NSString    *localVersion = [NSString stringWithFormat:@"%@",infoDic[@"CFBundleShortVersionString"]];
    NSString    *versionUrl =[NSString stringWithFormat:@"%@/latoutiao/version/getNewVersionNum",BASE_URL];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"versionNumber"] = localVersion;
    param[@"osType"] = @"1";
 
    [[ChainNetAPIClient sharedJsonClient]postRequestJsonDataWithPath:versionUrl withParams:param withHeader:nil andBlock:^(id data, NSError *error) {
        NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithDictionary:data];
        if ([dic[@"status"] isEqualToString:@"OK"]) {
           NSMutableDictionary * mDic= dic[@"map"];
            if (mDic) {
                NSString *isUpdate = [NSString stringWithFormat:@"%@",mDic[@"isUpdate"]];
                NSString *newVersionNumber = [NSString stringWithFormat:@"%@",infoDic[@"newVersionNumber"]];
                if ([isUpdate isEqualToString:@"1"]) {//是否有新的版本
#if defined(DEBUG)||defined(_DEBUG)
                    block(NO,newVersionNumber);
#else
                    block(YES,newVersionNumber);
#endif
                }else{
                    block(NO,@"");
                }
            }else{
                block(NO,@"");
            }
        }else{
            block(NO,@"");
        }
    }];
}
@end
